package cn.zynworld.saas.user.service.remote;

import cn.zynworld.saas.user.api.dto.UserDTO;
import cn.zynworld.saas.user.api.result.ResultBean;
import cn.zynworld.saas.user.api.service.UserRemoteService;
import cn.zynworld.saas.user.biz.domain.User;
import cn.zynworld.saas.user.biz.mappers.UserMapper;
import cn.zynworld.saas.user.service.converter.UserConverter;
import com.dianping.pigeon.remoting.provider.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created by zhaoyuening on 2018/1/20.
 */

@Service(url = "http://service.dianping.com/zynworld/saasUserService/userRemoteServiceImpl")
public class UserRemoteServiceImpl implements UserRemoteService {

    @Autowired
    private UserMapper userMapper;

    public ResultBean<Integer> add(UserDTO userDTO) {
        ResultBean<Integer> resultBean = new ResultBean<Integer>();
        User user = UserConverter.userDTO2user(userDTO);
        userMapper.insert(user);
        if (user != null && user.getId()!=null ){
            return resultBean.setStatus(200).setSuccess(true).setData(user.getId());
        }
        return resultBean.setSuccess(false).setStatus(400);
    }
}
